<template>
	<view class="zbTips">
		<view class="main">
			<view class="title"> 请投入纸币1 </view>
			<!-- <view>数据集合1: {{ messageArr }}</view>
			<view>数据集合2: {{ messageSendArr }}</view>
			<view>数据集合1和 = {{ countMoney(messageArr) }}</view>
			<view>数据集合2和 = {{ countMoney(messageSendArr) }}</view> -->
			<view class="money_total">{{ `应付款：${payable}` }}</view>
			<view class="money_total">
				{{ `已投入 ${messageArr.length?countMoney(messageArr):0} 圆` }}
			</view>
			<!-- <view class="money_total">
				{{ messageArr }}
			</view> -->
			<div class="btn_box">
				<view class="btn" @click="cancel">取消</view>
				<view class="btn" @click="confirm">确认</view>
			</div>
		</view>
	</view>
</template>

<script>
	import useStore from '@/store/index.js';
	import {
		countMoney
	} from '@/utils/countMoney';
	import {
		watch
	} from 'vue';
	import {
		saveSlotLog
	} from '@/api/order';
	import {
		zbCode,
		ybCode,
		zlCode,
		stateCode
	} from '@/config/code';

	export default {
		props: {
			messageArr: {
				default: [],
			},
			messageSendArr: {
				default: [],
			},
			payable: {
				default: 0,
			},
			orderNo: {
				default: '',
			},
		},
		data() {
			return {
				total: 0,
				baseTotal: 0, // 需要找零的总计
			};
		},
		// watch: {
		// 	payable: {
		// 		handler(newName, oldName) {
		// 			if (newName < countMoney(this.$props.messageArr)) {
		// 				const zl = newName - countMoney(this.$props.messageArr);
		// 				this.$emit('tbSuccess', {
		// 					type: 'zb',
		// 					change: zl
		// 				});
		// 			}
		// 			console.log('newName', newName);
		// 		},
		// 		immediate: true,
		// 	},
		// },
		mounted() {},
		methods: {
			jump(data) {
				let url = '';
				switch (data) {
					case 'service':
						url = '/pages/service/service';
						break;
					default:
				}
				uni.navigateTo({
					url,
				});
			},
			isNeedCoin() {
				const {
					order
				} = useStore();
				const needPayMoney = 200;
			},
			// 确认本次纸币投币
			confirm() {
				this.$emit('handConform', 'zb');
				this.$emit('handCountMoney', this.baseTotal);
			},
			// 取消本次纸币投币
			cancel() {
				this.$emit('handCanel', 'zb');
			},
			// 计算投币总额
			async countMoney(data) {
				if(!data.length){
					return 0
				}
				const equipmentOptions = JSON.parse(
					uni.getStorageSync('equipmentOptions')
				);
				let _total = 0;
				data.map(item => {
					_total += countMoney(item, this.total);
				});
				// this.baseTotal = _total;
				
				this.baseTotal = _total - this.payable
				
				// 后台通信记录投币记录
				if (
					data === zbCode.money_100 ||
					data === zbCode.money_500 ||
					data === zbCode.money_1000 ||
					data === ybCode.money_50
				) {
					const params = {
						store_id: equipmentOptions.store_id,
						order_no: this.$props.orderNo,
						equipmentID: equipmentID.equipmentID,
						amount: this.$props.payable,
						amount_type: 1,
						type: 1,
						num: 1,
						denomination: data,
					};
					await saveSlotLog(params).then(res => {});
				}
				return _total;
			},
		},
	};
</script>

<style lang="scss" scoped>
	.zbTips {
		position: fixed;
		top: 0;
		left: 0;
		z-index: 99;
		width: 100%;
		height: 100%;
		background: rgba(0, 0, 0, 0.5);
		display: flex;
		justify-content: center;
		align-items: center;

		.main {
			// width: 100%;
			// height: 100%;
			padding: 30rpx 60rpx;
			border: 2rpx solid $uni-color-green;
			border-radius: 10rpx;
			color: $uni-color-green;
			background-color: $uni-color-white;
			display: flex;
			flex-direction: column;
			justify-content: space-between;

			.title {
				width: 400rpx;
				height: 150rpx;
				text-align: center;
				line-height: 150rpx;
			}

			.money_total {
				height: 100rpx;
				text-align: center;
				line-height: 100rpx;
			}

			.btn_box {
				width: 400rpx;
				height: 100rpx;
				display: flex;
				justify-content: space-between;

				.btn {
					height: 30rpx;
					padding: 20rpx;
					line-height: 1;
					border-radius: 10rpx;
					color: $uni-color-white;
					background-color: $uni-color-green;
				}
			}
		}
	}
</style>